var express = require('express');
var router = express.Router();
const connection = require('../db/sql.js');
const user = require('../db/UserSql.js');
//短信验证码
var QcloudSms = require("qcloudsms_js");
//token
let jwt = require('jsonwebtoken');
//支付宝支付
const alipaySdk = require('../db/alipay.js');
const AlipayFormData = require('alipay-sdk/lib/form').default;
//axios
let axios = require('axios');
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

//支付状态
router.post('/api/queryOrderAlipay',function(req,res,next){
	//用户token
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//订单号
	let out_trade_no = req.body.out_trade_no;
	let trade_no = req.body.trade_no;

	//支付宝配置
	const formData = new AlipayFormData();
	formData.setMethod('get');
	//支付成功，返回的页面
	formData.addField('bizContent', {
	   out_trade_no,
	   trade_no
	});
	
	const result = alipaySdk.exec(
	  'alipay.trade.query',
	  {},
	  { formData: formData },
	);
	
	//后端请求支付宝
	result.then(resData=>{
		axios({
			method:"GET",
			url:resData
		}).then(data=>{
			let r = data.data.alipay_trade_query_response;
			//订单一切ok[调用成功]
			if( r.code ==='10000' ){
				switch( r.trade_status ){
					case 'WAIT_BUYER_PAY':
						res.send({
							code:0,
							data:{
								success:true,
								msg:'支付宝有交易记录，没付款'
							}
						})
						break;
					case 'TRADE_FINISHED':
						res.send({
							code:0,
							data:{
								success:true,
								msg:'交易完成，不可退款'
							}
						})
						break;
					case 'TRADE_SUCCESS':
						//查询用户
						connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
							let userId = results[0].id;
							//查询当前用户的订单号
							connection.query(`select * from shop_orders where uId = ${userId} and order_id = ${out_trade_no}`,function(err,result){
								let id = result[0].id;
								//当前用户的订单号的状态1改成2
								connection.query(`update shop_orders set order_status = replace(order_status,'2','3') where id = ${id}`,function(e,r){
									res.send({
										code:0,
										data:{
											success:true,
											msg:'交易成功'
										}
									})
								})
							})
						})
						break;
					case 'TRADE_CLOSED':
						//查询用户
						connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
							let userId = results[0].id;
							//查询当前用户的订单号
							connection.query(`select * from shop_orders where uId = ${userId} and order_id = ${out_trade_no}`,function(err,result){
								let id = result[0].id;
								//当前用户的订单号的状态1改成2
								connection.query(`update shop_orders set order_status = replace(order_status,'2','0') where id = ${id}`,function(e,r){
									res.send({
										code:0,
										data:{
											success:true,
											msg:'未付款或者超时'
										}
									})
								})
							})
						})
						
						break;
				}
			}else if( r.code ==='40004'){
				res.send({
					code:0,
					data:{
						success:true,
						msg:'交易不存在'
					}
				})
			}
		}).catch(err=>{
			res.send({
				code:0,
				data:{
					msg:'查询失败',
					err
				}
			})
		})
	})
	
	
})

//发起==》支付宝支付
router.post('/api/payment',function(req,res,next){
	//订单号
	let orderId = req.body.orderId;
	//总价
	let goodsPrice = req.body.goodsPrice.toString();
	//名称
	let goodsName = req.body.goodsName;
	//支付宝格式
	const formData = new AlipayFormData();
	// 调用 setMethod 并传入 get，会返回可以跳转到支付页面的 url
	formData.setMethod('get');
	//支付成功，返回的页面
	formData.addField('bizContent', {
	  //订单号 
	  outTradeNo: orderId,
	  //写死
	  productCode: 'FAST_INSTANT_TRADE_PAY',
	  //金额
	  totalAmount: goodsPrice,
	  //商品标题
	  subject: goodsName
	});
	
	//支付成功或者失败，跳转的链接
	formData.addField('returnUrl', 'http://localhost:8080/pay-success');
	
	const result = alipaySdk.exec(
	  'alipay.trade.page.pay',
	  {},
	  { formData: formData },
	);
	
	// result 为可以跳转到支付链接的 url
	result.then(resp=>{
		res.send({
			code:0,
			data:{
				success:true,
				msg:'支付中...',
				paymentUrl:resp
			}
		})
	})
	
})

//提交订单
router.post('/api/submitOrder',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//订单号
	let orderId = req.body.orderId;
	//选择的购物车id
	let shopArr = req.body.shopArr;
	//查询用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		//查询当前用户的订单号
		connection.query(`select * from shop_orders where uId = ${userId} and order_id = ${orderId}`,function(err,result){
			let id = result[0].id;
			//当前用户的订单号的状态1改成2
			connection.query(`update shop_orders set order_status = replace(order_status,'1','2') where id = ${id}`,function(e,r){
				shopArr.forEach(v=>{
					//删除购物车数据
					connection.query(`delete from goods_cart where id = ${v}`,function(){
						res.send({
							code:0,
							data:{
								success:true
							}
						})
					})
				})
			})
		})
	})
})
//生成一个订单
router.post('/api/addOrder',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	let goodsArr = req.body.arr;

	//订单号===》时间戳+6位随机数
	function setTimeDateFmt(s) {  // 个位数补齐十位数
	  return s < 10 ? '0' + s : s;
	}
	function randomNumber() {
	  const now = new Date()
	  let month = now.getMonth() + 1
	  let day = now.getDate()
	  let hour = now.getHours()
	  let minutes = now.getMinutes()
	  let seconds = now.getSeconds()
	  month = setTimeDateFmt(month)
	  day = setTimeDateFmt(day)
	  hour = setTimeDateFmt(hour)
	  minutes = setTimeDateFmt(minutes)
	  seconds = setTimeDateFmt(seconds)
	  let orderCode = now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math.round(Math.random() * 1000000)).toString();
	  return orderCode;
	}
	/*订单
	0:支付失败
	1:未支付
	2:待支付
	3:支付成功
	*/
   //商品列表
   let goodsName = [];
   //订单商品总数量
   let goodsNum = 0;
   //订单商品总价
   let goodsPrice = 0;
   
   goodsArr.forEach(v=>{
		goodsName.push( v.goods_name );
		goodsNum += v.goods_num;
		goodsPrice += v.goods_num * v.goods_price;
   })
   
   
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		//生成订单===》状态为：1
		connection.query(`insert into shop_orders (uId,order_id,goods_name,goods_price,goods_num,order_status) values ('${userId}','${randomNumber()}','${goodsName}','${goodsPrice}','${goodsNum}','1')`,function(err,result){
			
		})
		//查询返回订单号
		connection.query(`select * from shop_orders where uId=${userId} and order_status='1'`,function(err,result){
			res.send({
				code:0,
				data:result
			})
		})
	})
})


//删除 【收货地址】
router.post('/api/deleteAddress',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	let id = req.body.id;
	connection.query(`delete from address where id = ${id}`,function(error,results){
		res.send({
			code:0,
			data:{
				success:true,
				msg:'删除成功'
			}
		})
	})
})

//修改 【收货地址】
router.post('/api/updateAddress',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//前端给后端的参数
	let body = req.body;
	let [name,tel,province,city,district,address,isDefault,id] = [
		body.name,
		body.tel,
		body.province,
		body.city,
		body.district,
		body.address,
		body.isDefault,
		body.id
	]
	//确定哪个一个用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		connection.query(`select * from address where uId = ${userId} and isDefault = ${isDefault}`,function(error,result){
			let childId = result[0].id;
			connection.query(`update address set isDefault = replace(isDefault,'1','0') where id = ${childId}`,function(e,r){
				let updateSql = `update address set name = ? , tel = ? , province = ? , city = ? , district = ? , address = ? , isDefault = ? , uId = ? where id = ${id}`;
				connection.query(updateSql,[name,tel,province,city,district,address,isDefault,userId],function(error,result){
					res.send({
						code:0,
						data:{
							success:true,
							msg:'修改成功'
						}
					})
				})
			})
		})
	})
})

//新增 【收货地址】
router.post('/api/addAddress',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//前端给后端的参数
	let body = req.body;
	let [name,tel,province,city,district,address,isDefault] = [
		body.name,
		body.tel,
		body.province,
		body.city,
		body.district,
		body.address,
		body.isDefault
	]
	//确定哪个一个用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		if(  isDefault!=1 ){
			//没有选择默认地址
			connection.query(`insert into address (name,tel,province,city,district,address,isDefault,uId) values ('${name}','${tel}','${province}','${city}','${district}','${address}','${isDefault}','${userId}')`,function(err,result){
				res.send({
					code:0,
					data:{
						success:true,
						msg:'收货地址添加成功'
					}
				})
			})
		}else{
			//有
			connection.query(`select * from address where uId = ${userId} and isDefault = ${isDefault}`,function(err,result){
				let childId = result[0].id;
				connection.query(`update address set isDefault = replace(isDefault,'1','0') where id =${childId}`,function(err,data){
					connection.query(`insert into address (name,tel,province,city,district,address,isDefault,uId) values ('${name}','${tel}','${province}','${city}','${district}','${address}','${isDefault}','${userId}')`,function(e,r){
						res.send({
							code:0,
							data:{
								success:true,
								msg:'收货地址添加成功'
							}
						})
					})
				})
			})
		}
	})
})



//查询 【收货地址】
router.post('/api/selectAddress',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//确定哪个一个用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		connection.query(`select * from address where uId = ${userId}`,function(err,result){
			res.send({
				code:0,
				data:result
			})
		})
	})
})



//删除 【数据库数据】
router.post('/api/deleteCart',function(req,res,next){
	let id = req.body.id;
	connection.query(`delete from goods_cart where id = ${id}`,function(error,results){
		res.send({
			data:0,
			data:{
				success:true,
				msg:'删除成功'
			}
		})
	})
})
//修改 【数据库数据】
router.post('/api/updateNumCart',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//得到前端给后端的商品id
	let goodsId = req.body.goodsId;
	//得到前端给后端的修改数量
	let goodsNum = req.body.goodsNum;
	//查询当前用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		//查询到商品
		connection.query(`select * from goods_cart where uId = ${userId} and goods_id = ${goodsId}`,function(err,result){
			//数据库中原来到商品数量
			let num = result[0].goods_num;
			//当前数据库表中的id
			let id = result[0].id;
			connection.query(`update goods_cart set goods_num = replace(goods_num,${num},${goodsNum}) where id = ${id}`,function(e,r){
				res.send({
					code:0,
					data:{
						success:true,
						msg:'修改成功'
					}
				})
			})
		})
	})
})
//查询 【购物车数据】
router.post('/api/selectCart',function(req,res,next){
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//确定哪个一个用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		let userId = results[0].id;
		connection.query(`select * from goods_cart where uId = ${userId}`,function(err,result){
			res.send({
				code:0,
				data:result
			})
		})
	})
	
})

//增加 【购物车数据】
router.post('/api/addCart',function(req,res,next){
	
	let token = req.headers.token;
	let phone = jwt.decode(token);
	//商品id
	var goods_id = req.body.goodsId;
	//商品数量
	var goods_num = req.body.goodsNum;
	//查找到当前用户
	connection.query(`select * from user where phone = ${phone.name}`,function(error,results){
		//用户id
		let userId = results[0].id;
		//查询对应的商品
		connection.query(`select * from shoplist where id = ${goods_id}`,function(err,result){
			//商品名称
			let name = result[0].name;
			//商品价格
			let price = result[0].price;
			//商品图片
			let imgUrl = result[0].imgUrl;
			
			//查找当前用户之前有没有这条数据
			connection.query(`select * from goods_cart where uId = ${userId} and goods_id = ${goods_id}`,function(err,data){
				
				if( data.length > 0 ){
					//如果有就修改==>替换
					connection.query(`update goods_cart set goods_num = replace(goods_num,${data[0].goods_num},${   parseInt(data[0].goods_num) + parseInt(goods_num)  }) where id = ${data[0].id}`,function(e,r){
						res.send({
							code:0,
							data:{
								success:true,
								msg:'添加购物车成功'
							}
						})
					})
				}else{
					//如果没有就新增
					connection.query(`insert into goods_cart (goods_id,goods_name,goods_num,goods_price,goods_imgUrl,uId) values ('${goods_id}','${name}','${goods_num}','${price}','${imgUrl}','${userId}')`,function(e,r){
						res.send({
							code:0,
							data:{
								success:true,
								msg:'添加购物车成功'
							}
						})
					})
				}
				
			})
		})
	})
	
})


//判断是否有用户===》no增加用户  yes就不增加  : 总之要返回用户信息
router.post('/api/addUser',function(req,res,next){
	
	//后端拿到前端传递过来的数据==>手机号
	let params = {
		userName:req.body.phone
	}
	//查询用户是否存在
	connection.query( user.queryUserName( params ),function(error,results){
		//如果数据存在
		if( results.length > 0 ){
			res.send({
				code:0,
				data:{
					success:true,
					msg:'登录成功',
					data:results[0]
				}
			})
		}else{
			//如果没有新增一条数据
			connection.query( user.insertData( params ) ,function(err,result){
				//查询结果给前端返回用户数据
				connection.query( user.queryUserName( params ) ,function(e,r){
					res.send({
						code:0,
						data:{
							success:true,
							msg:'注册并且登录成功',
							data:r[0]
						}
					})
				})
			})
		}
	})
})



//发送短信验证码
router.post('/api/code',function(req,res,next){
	
	//后端拿到前端传递过来的数据==>手机号
	let tel = req.body.phone;
	
	// 短信应用 SDK AppID
	var appid = 1400187558;  // SDK AppID 以1400开头
	// 短信应用 SDK AppKey
	var appkey = "dc9dc3391896235ddc2325685047edc7";
	// 需要发送短信的手机号码
	var phoneNumbers = [tel];
	// 短信模板 ID，需要在短信控制台中申请
	var templateId = 285590;  // NOTE: 这里的模板ID`7839`只是示例，真实的模板 ID 需要在短信控制台中申请
	// 签名
	var smsSign = "三人行慕课";  // NOTE: 签名参数使用的是`签名内容`，而不是`签名ID`。这里的签名"腾讯云"只是示例，真实的签名需要在短信控制台申请
	// 实例化 QcloudSms
	var qcloudsms = QcloudSms(appid, appkey);
	// 设置请求回调处理, 这里只是演示，用户需要自定义相应处理回调
	function callback(err, ress, resData) {
	  if (err) {
	      console.log("err: ", err);
	  } else {
		  res.send({
			  code:0,
			  data:{
				  success:true,
				  data:ress.req.body.params[0]
			  }			 
		  })
	  }
	}
	
	var ssender = qcloudsms.SmsSingleSender();
	var params = [  Math.floor( Math.random()*(9999-1000))+1000 ];
	ssender.sendWithParam("86", phoneNumbers, templateId,
	params, smsSign, "", "", callback); 
	
})

//登录
router.post('/api/login',function(req,res,next){
	//后端拿到前端传递过来的数据
	let params = {
		userName : req.body.userName,
		userPwd  : req.body.userPwd
	}
	//查询用户名或者手机号是否存在
	connection.query( user.queryUserName( params )  ,function(error,results){
		
		if( results.length > 0 ){
			//用户名和手机号存在
			
			connection.query( user.queryUserPwd( params ) ,function(error,result){
				
				if( result.length > 0  ){
					
					res.send({
						code:0,
						data:{
							success:true,
							msg:'登录成功',
							data:result[0]
						}
					})
					
				}else{
					//密码不对
					res.send({
						code:0,
						data:{
							success:false,
							msg:'密码不对'
						}
					})
					
				}
				
			})
			
		}else{
			//用户名和手机号  不   存在
			res.send({
				code:0,
				data:{
					success:false,
					msg:'用户名或手机号不存在'
				}
			})
		}
		
		
		
	})
	
})

//根据id查询对应商品
router.get('/api/goods/id',function(req,res,next){
	let id = req.query.id;
	connection.query('select * from shoplist where id='+id+'',function(error,result){
		
		if( error ) throw error;
		res.json({
			code:0,
			data:result
		})
	})
	
})


//商品接口
router.get('/api/goods/shopList',function(req,res,next){
	
	let [searchName,orderName] = Object.keys(req.query);
	let [name,order] = Object.values( req.query );
	
	connection.query('select * from shoplist where name like "%'+name+'%" order by '+orderName+' '+order+'',function(error,results){

		res.send({
			code:0,
			data:results
		})
		
	})
	
})


//分类数据
router.get('/api/goods/list',function(req,res,next){
		
	res.send({
		code:0,
		data:[
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:1,
				name:'RedMi手',
				data:[//二级
					{
						id:0,
						name:'Redmi红米 Note系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:2,
				name:'游戏手机',
				data:[//二级
					{
						id:0,
						name:'游戏手机',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			},
			{//一级
				id:0,
				name:'小米手机',
				data:[//二级
					{
						id:0,
						name:'小米数字系列',
						list:[//三级
							{
								id:0,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:1,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:2,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							},
							{
								id:3,
								name:'小米11Pro',
								imgUrl:"./img/list1.png"
							}
						]
					}
				]
			}
		]
	})
	
})

//首页智能数据===》 第一次数据
router.get('/api/index_list/2/data/1',function(req,res,next){
	res.send({
		code:0,
		data:[
			//这是swiper的
			{
				id:0,
				type:'swiperList',
				data:[
					{id:0,imgUrl:'./img/swiper1.jpeg'},
					{id:1,imgUrl:'./img/swiper2.jpeg'}
				]
			},
			//adList
			{
				id:1,
				type:"adList",
				data:[
					{
						id:0,
						imgUrl:'./img/ad.jpg'
					}
				]
			}
		]
	})
})
//首页手机数据===》 第一次数据
router.get('/api/index_list/1/data/1',function(req,res,next){
	res.send({
		code:0,
		data:[
			//adList
			{
				id:0,
				type:"adList",
				data:[
					{
						id:0,
						imgUrl:'./img/ad.jpg'
					}
				]
			}
		]
	})
})
//首页推荐数据===》 第一次数据
router.get('/api/index_list/0/data/1',function(req,res,next){
	res.send({
		code:0,
		data:{
			topBar:[
				{id:0,label:'推荐',},
				{id:1,label:'手机',},
				{id:2,label:'智能',},
				{id:3,label:'电视',},
				{id:4,label:'家电',},
				{id:5,label:'笔记本',},
				{id:6,label:'台式机',}
			],
			data:[
				//这是swiper的
				{
					id:0,
					type:'swiperList',
					data:[
						{id:0,imgUrl:'./img/swiper1.jpeg'},
						{id:1,imgUrl:'./img/swiper2.jpeg'}
					]
				},
				//icons数据
				{
					id:1,
					type:'iconsList',
					data:[
						{id:0,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:1,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:2,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:3,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:4,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:5,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:6,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:7,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:8,imgUrl:'./img/icons1.jpg',title:'小米秒杀'},
						{id:9,imgUrl:'./img/icons1.jpg',title:'小米秒杀'}
					]
				},
				//recommendList数据
				{
					id:2,
					type:'recommendList',
					data:[
						{
							id:0,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:1,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:2,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:3,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:4,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:5,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:0,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:1,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:2,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:3,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:4,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:5,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:0,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:1,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:2,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:3,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:4,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:5,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:0,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:1,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:2,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:3,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:4,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:5,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:0,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:1,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:2,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:3,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:4,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:5,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:0,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:1,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:2,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:3,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						},
						{
							id:4,
							imgUrl:'./img/recommend1.jpeg',
							name:'小米手机1',
							content:'这是一个好手机',
							pprice:'1299'
						},
						{
							id:5,
							imgUrl:'./img/recommend2.jpeg',
							name:'小米手机2',
							content:'这是2个好手机',
							pprice:'2299'
						}
					]
				},
			]
			
		}
	})
	
})

module.exports = router;
